<?php

namespace App\V3\V3_2_7\Services;

use App\V3\V3_2_7\Models\TallyClassModel;
use App\V3\V3_2_7\Models\TallyModel;

/**
 * 收支
 * Class IncomeExpensesService
 * @package App\Services
 */
class IncomeExpensesService
{
    /**
     * 销售退款收支入库记账单
     * change 在 2022/1/24 10:57 创建
     * @param $type 0-销售 1-退货
     * @param $orderNo  订单号
     * @param $money    金额
     * @param $mainId   主账号
     * @return int      成功返回1
     */
    static public function tally($type,$orderNo,$money,$mainId,$date,$payType = 0,$userId = 0){
        $data = [];
        if($type==0){
            $data['tally_class_name'] = '销售';
            $data['type'] = 0;
        }elseif($type==1){
           
            $data['tally_class_name'] = '退货';
            $data['type'] = 1;
        }elseif($type == 2){
            $data['tally_class_name'] = '退换货';
            $data['type'] = $payType;
        }
        $data['money'] = $money;
        $data['order_no'] = $orderNo;
        $data['main_id'] = $mainId;
        $data['user_id'] = $userId;
        $data['add_time'] = strtotime($date);
        $data['created_at'] = time();
        $data['updated_at'] = time();
        TallyModel::insert($data);
        return 1;
    }
}
